package com.song.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @ClassName : RedisController
 * @Author : 司猫子
 * @Date: 2021/3/2 0:49
 */
@RestController
public class RedisController {

    @Resource
    private RedisTemplate redisTemplate;

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @GetMapping("/redis/{k}/{v}")
    public String toredis(@PathVariable("k") String k,@PathVariable("v") String v){
        stringRedisTemplate.opsForValue().set(k, v);
        return "成功设置了redis的value:"+v;
    }

    @GetMapping("/redis/{k}")
    public String getredis(@PathVariable("k") String k){
        String s = stringRedisTemplate.opsForValue().get(k);
        return "拿到了redis的值为:"+s;
    }
}
